package com.mytest.myID;

import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class MyUUID {
    public static void main(String[] args) throws InterruptedException {

        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor
                (3, 10, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<>(20));
        for (int i = 0; i < 20; i++) {
            if (poolExecutor.getActiveCount() <= poolExecutor.getMaximumPoolSize()) {
                poolExecutor.execute(() -> {
                    try {
                        System.out.println(getUUID());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                });
            }
        }
        TimeUnit.SECONDS.sleep(3);
        poolExecutor.shutdown();
    }

    public static String getUUID() {
        return UUID.randomUUID().toString().replace("-","");
    }
}